package com.magnificent.atlantis.client.ui.planner.panels.task.treetable.renderers;

import com.magnificent.atlantis.client.data.task.planner.AbstractPlannerTask;
import com.magnificent.atlantis.client.ui.planner.panels.task.treetable.data.PlannerTableNode;

import javax.swing.*;
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.*;

/**
 * User: Babanin
 * Date: 11.03.2009
 * Time: 17:49:33
 */
public class PlannerTreeCellRenderer extends DefaultTreeCellRenderer {
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        PlannerTableNode tableNode = (PlannerTableNode) value;
        JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

        AbstractPlannerTask plannerTask = tableNode.getTask();
        if (plannerTask != null) {
            String taskName = plannerTask.getName();

            if (plannerTask.isFinished()) {
                label.setText("<html><font color=gray><s>" + taskName + "</s></font></html>");
            } else {
                label.setText(taskName);
            }
        }

        return label;
    }
}
